package com.zmj.workorder.service;


import com.zmj.workorder.bean.TableData;
import com.zmj.workorder.bean.WorkOrder;
import com.zmj.workorder.mapper.WorkOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class WorkOrderService {

    @Resource
    private WorkOrderMapper workOrderMapper;

    public  boolean savaWorkOrder(WorkOrder workOrder){
    long time=System.currentTimeMillis();
        Date date =new Date(time);
        workOrder.setCreate_time(date);
       return workOrderMapper.savaWorkOrder(workOrder)>0;
    }

    public List<WorkOrder> getWorkOrder(){
     return workOrderMapper.getWorkOrder();
    }

    public TableData findByPage(int offset, int limit, String   order, String   search) {
        TableData  data = new TableData();

        List<WorkOrder> list = workOrderMapper.findByPage(offset,limit,order,search);
        long  total = workOrderMapper.findTotalCount(search);

        data.setTotal(total);
        data.setRows(list);
        return data;
    }
}
